package com.itheima.easy.web;

import com.itheima.easy.handler.PayNotifyHandler;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 支付回调接口
 */
@RestController
@RequestMapping("pay-notify")
@Slf4j
@Api(tags = "支付通道controller")
public class PayNotifyController {

    @Autowired
    PayNotifyHandler aliPayNotifyHandler;

    @Autowired
    PayNotifyHandler wechatPayNotifyHandler;

    /***
     *  支付宝支付回调
     */
    @PostMapping("ali-pay-notify/{enterpriseId}")
    String aliPayNotify(HttpServletRequest request, HttpEntity<String> httpEntity,
                        @PathVariable("enterpriseId") String enterpriseId){
        log.info("==========支付宝通知接口enterpriseId：{}",enterpriseId);
        return aliPayNotifyHandler.notify(request,httpEntity,enterpriseId);
    }

    /***
     *  微信支付回调
     */
    @PostMapping("wechat-pay-notify/{enterpriseId}")
    String wechatPayNotify(HttpServletRequest request, HttpEntity<String> httpEntity,
                           @PathVariable("enterpriseId") String enterpriseId){
        log.info("===============微信通知接口enterpriseId：{}",enterpriseId);
        return wechatPayNotifyHandler.notify(request,httpEntity,enterpriseId);
    }
}
